package com.wdb.modules.system.rest;

import com.wdb.modules.system.domain.DictDetail;
import com.wdb.modules.system.domain.vo.QueryDictDetailReqDTO;
import com.wdb.modules.system.service.DictDetailService;
import com.wdb.utils.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 数据字典
 *
 * @author: wendaobai@qq.com
 * @date: 2024/1/22 0022 15:51
 */
@RestController
@Api(tags = "系统：字典详情管理")
@RequestMapping("/api/dictDetail")
@RequiredArgsConstructor
@Slf4j
public class DictDetailController {
  private final DictDetailService dictDetailService;

  @ApiOperation("查询字典详情")
  @GetMapping("")
  public ResponseEntity<Object> queryDictDetail(QueryDictDetailReqDTO queryDictDetailReqDTO) {
    PageResult<DictDetail> pageResult = dictDetailService.findAll(queryDictDetailReqDTO);

    return new ResponseEntity(pageResult, HttpStatus.OK);
  }

  @ApiOperation("新增字典")
  @PostMapping
  public ResponseEntity<Object> createDictDetail(@Validated @RequestBody DictDetail resource) {
    dictDetailService.create(resource);
    return new ResponseEntity<>(HttpStatus.CREATED);
  }
  @ApiOperation("修改字典")
  @PutMapping
  public ResponseEntity<Object> updateDictDetail(@Validated @RequestBody DictDetail resource){
    dictDetailService.update(resource);
    return  new ResponseEntity<>(HttpStatus.OK);
  }
  @ApiOperation("删除字典")
  @DeleteMapping
  public ResponseEntity<Object> deleteDictDetail(@PathVariable Long id){
    dictDetailService.delete(id);
    return new ResponseEntity<>(HttpStatus.OK);
  }


}
